//
//  main.m
//  3+...的前20项之和
//
//  Created by apple on 15/7/27.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        //定义函数变量以及赋初值
        float t;
        float a = 2,b = 1;
        float s = 0;
        int number = 20;
        
        //主题函数部分
        for (int n = 1; n <= number; n++)
        {
            //float a = 2,b = 1;    （加在for里面的话，分子分母就一直为2，1，也就是20个2相加，不是我们要的结果。
            s = s + a/b;
            t = a,a = a + b,b = t;
        }
        //输出这20项相加和s的值
        NSLog(@"%f",s);
        
       /* int n,t,number = 20;
        float a = 2,b = 1,s = 0;
        for (n = 1; n <= number; n++)
        {
            s = s + a/b;
            t = a,a = a + b,b = t;
        }
        printf("Sum is %f\n",s);
        printf("Sum is %9.6f\n",s);*/
        
    }
    return 0;
}
